/*
 * Copyright (c) 2025 Industrial Software Feature Database
 */
package com.comac.ins.isfd.service.impl;


import java.util.List;
import java.util.stream.Collectors;

import org.springframework.stereotype.Service;

import cn.hutool.core.collection.CollectionUtil;
import com.anwen.mongo.conditions.query.LambdaQueryChainWrapper;
import com.anwen.mongo.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.comac.ins.isfd.domain.bo.FastenerOriginalInfoBo;
import com.comac.ins.isfd.domain.bo.query.FastenerOriginalInfoQueryBo;
import com.comac.ins.isfd.service.IFastenerOriginalInfoService;
import lombok.extern.slf4j.Slf4j;

/**
 * 紧固件原始service实现类
 *
 * @author wujialin
 * @date 2025-6-15
 */
@Slf4j
@Service
public class IFastenerOriginalInfoServiceImpl extends ServiceImpl<FastenerOriginalInfoBo> implements IFastenerOriginalInfoService {


    @Override
    public List<FastenerOriginalInfoBo> queryPageList(FastenerOriginalInfoQueryBo bo) {
        List<FastenerOriginalInfoBo> fastenerOriginalInfoBoList;
        // 构造查询参数
        LambdaQueryChainWrapper<FastenerOriginalInfoBo> queryChainWrapper = this.lambdaQuery();
        if (StringUtils.isNotBlank(bo.getNameSource()) && CollectionUtil.isNotEmpty(bo.getFastenerGradeList())) {
            queryChainWrapper
                .like(StringUtils.isNotBlank(bo.getTypeSource()), FastenerOriginalInfoBo::getTypeSource, bo.getTypeSource())
                .eq(StringUtils.isNotBlank(bo.getUnit()), FastenerOriginalInfoBo::getUnit, bo.getUnit())
                .in(CollectionUtil.isNotEmpty(bo.getFastenerGradeList()), FastenerOriginalInfoBo::getNameSource, bo.getFastenerGradeList())
                .in(CollectionUtil.isNotEmpty(bo.getIdList()), FastenerOriginalInfoBo::get_id, bo.getIdList());
            fastenerOriginalInfoBoList = this.list(queryChainWrapper);
            fastenerOriginalInfoBoList = fastenerOriginalInfoBoList.stream()
                .filter(item -> item.getNameSource() != null
                    && item.getNameSource().contains(bo.getNameSource()))
                .collect(Collectors.toList());
        } else {
            queryChainWrapper
                .like(StringUtils.isNotBlank(bo.getNameSource()), FastenerOriginalInfoBo::getNameSource, bo.getNameSource())
                .like(StringUtils.isNotBlank(bo.getTypeSource()), FastenerOriginalInfoBo::getTypeSource, bo.getTypeSource())
                .eq(StringUtils.isNotBlank(bo.getUnit()), FastenerOriginalInfoBo::getUnit, bo.getUnit())
                .in(CollectionUtil.isNotEmpty(bo.getFastenerGradeList()), FastenerOriginalInfoBo::getNameSource, bo.getFastenerGradeList())
                .in(CollectionUtil.isNotEmpty(bo.getIdList()), FastenerOriginalInfoBo::get_id, bo.getIdList());
            fastenerOriginalInfoBoList = this.list(queryChainWrapper);
        }

        return fastenerOriginalInfoBoList;
    }
}
